package com.estar.app.business.common.utils;

import java.io.File;

import org.apache.log4j.Logger;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Zip;
import org.apache.tools.ant.types.FileSet;

import com.estar.platform.caseInfo.utils.FileOperationUtil;

public class CompressFile {
	
	private File zipFile;   
	  
    public  CompressFile(String pathName) {   
       zipFile = new File(pathName);   
   }  
	private static final Logger logger = Logger.getLogger(CompressFile.class);
	/** 
     * 执行压缩操作 
     * @param srcPathName 需要被压缩的文件/文件夹 
	 * @throws Exception 
     */  
    public void compressExe(String srcPathName) {    
    	try {
    	File srcdir = new File(srcPathName);    
        if (!srcdir.exists()){  
            
				throw new Exception(srcPathName + "不存在！");
			   
        }   
        Project prj = new Project();    
        Zip zip = new Zip();    
        zip.setProject(prj);    
        zip.setDestFile(zipFile);    
        FileSet fileSet = new FileSet();    
        fileSet.setProject(prj);    
        fileSet.setDir(srcdir);    
        zip.addFileset(fileSet);    
        zip.execute();   
    	} catch (Exception e) {
			logger.error("生成压缩包错误：", e);
			e.printStackTrace();
		} 
    }    
    
    public static void main(String[] args) {
    	//c.compressExe("D:\\Study\\小丹丹");
	}
}
